﻿using Quartz;
using System.Reflection;

namespace QiAdmin.Core.Services.QuartzService
{
    public class AssemblyService : BaseJobService, IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            Execute(context, () =>
            {
                JobDataMap dataMap = context.JobDetail.JobDataMap;
                Assembly assembly = Assembly.Load(App.StaticData.TaskAssembly);

                var type = assembly.GetType(App.StaticData.TaskAssembly + "." + context.JobDetail.Key.Group);
                object instance = Activator.CreateInstance(type);
                var method = type.GetMethod("Execute");
                bool result = (bool)method.Invoke(instance, new object[] { dataMap });
                return result;
            });
            return Task.CompletedTask;
        }
    }
}
